package com.cdc.rxjava;

import android.graphics.Bitmap;

import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;

/**
 * Created by cdc on 2018/3/30.
 */

public class RxjavaOperatorDemo {
    private void map() {

        Observable.just("map/image/map.png").map(new Function<String, Bitmap>() {
            @Override
            public Bitmap apply(String s) throws Exception {
                return null;
            }
        }).subscribe(new Consumer<Bitmap>(){
            @Override
            public void accept(Bitmap bitmap) throws Exception {
                showBitmap(bitmap);
            }
        });
    }

    private void showBitmap(Bitmap bitmap) {
        // TODO: 2017/10/7
    }

    private Bitmap getBitmap(String filePath) {
        return null;
    }

    private Disposable processNetAddress() {
        return Observable.just(
                "http://www.baidu.com/",
                "https://www.sina.com/",
                "https://www.sohu.com/")
                .flatMap(new Function<String, Observable<String>>() {
                    @Override
                    public Observable<String> apply(String s) throws Exception {
                        return createObservable(s);
                    }
                })
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String s) throws Exception {

                    }
                });
    }

    private Observable<String> createObservable(String s) {
        return null;
    }
}
